﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _19对话框综合示例
{
    public class MyEnttitys
    {
        List<Entity> ents = new List<Entity>();
        public List<Entity> Ents
        {
            get { return ents; }
        }
        public MyEnttitys(double width, double height, double radius)
        {
            if (radius * 2 <= width && radius * 2 <= height)
            {
                if (radius * 2 == width && radius * 2 == height)
                {
                    Circle circle = new Circle(new Point3d(radius, -radius,0), Vector3d.ZAxis, radius);
                    ents.Add(circle);
                }
                else
                {
                    Line lineTop = new Line(new Point3d(0, 0, 0), new Point3d( width, 0, 0));
                    Line lineRight = new Line(lineTop.EndPoint,new Point3d(width,-height,0));
                    Line lineBottom = new Line(lineRight.EndPoint,new Point3d(0,-height,0));
                    Line lineLeft = new Line(lineBottom.EndPoint,lineTop.StartPoint);
                    ents.Add(lineTop);
                    ents.Add(lineRight);
                    ents.Add(lineBottom);
                    ents.Add(lineLeft);
                    if (radius > 0)
                    {
                        List<Entity> arcEnts = lineLeft.GetArcFrom2Lines(lineTop, radius);
                        if (arcEnts.Count >0 )
                        {
                            ents.Add(arcEnts[0]);
                        }
                        arcEnts = lineTop.GetArcFrom2Lines(lineRight, radius);
                        if (arcEnts.Count > 0)
                        {
                            ents.Add(arcEnts[0]);
                        }
                        arcEnts = lineRight.GetArcFrom2Lines(lineBottom, radius);
                        if (arcEnts.Count > 0)
                        {
                            ents.Add(arcEnts[0]);
                        }
                        arcEnts = lineBottom.GetArcFrom2Lines(lineLeft, radius);
                        if (arcEnts.Count > 0)
                        {
                            ents.Add(arcEnts[0]);
                        }

                    }
                   

                }
            }
            
        }
    }
}
